<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	private $appid;
	private $secret;
	private $redirect_uri;
	private $scope;

	function __construct(){
		parent::__construct();
		$this->appid='wx9e9fbb29f715815a';//微信第三方平台绑定网站应用成功自动生成的
		$this->secret='3290ca5dbac5b5bc5d5fab501f1fda6b';//微信第三方平台秘钥
		$this->redirect_uri='http://www.xiyuxiaguang.com/Home/Index/wxlogin'; //扫码之后跳转的页面
		$this->scope='snsapi_login';//网页应用目前仅填写snsapi_login即可
	}
    public function index(){
        $this->display();
    }

    public function wx_login(){
        $this->$appid;
    	$url="https://open.weixin.qq.com/connect/qrconnect?appid=".$this->appid."&redirect_uri=".$this->redirect_uri."&response_type=code&scope=".$this->scope."&state=STATE#wechat_redirect";//请求code
    	$ret['code']=200;
        $ret['url']=$url;
        $this->ajaxReturn($ret);

    }

    public function wxlogin(){
    	$code=I('get.code');
    	$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->secret."&code=".$code."&grant_type=authorization_code";
    	$res_data=HttpRequst($url); //获取到access_token
    	$res_arr=json_decode($res_data,true);
    	// echo $res_arr['access_token'];
    	// echo '...................';
    	// echo $res_arr['openid'];
    	// exit();
    	//通过access_token获取用户信息
    	$get_user_url="https://api.weixin.qq.com/sns/userinfo?access_token=".$res_arr['access_token']."&openid=".$res_arr['openid'];
    	$user_data=HttpRequst($get_user_url);
    	$user_arr=json_decode($user_data,true);
    	print_r($user_arr);

    }
}